home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / test / forms.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  7.5 KB  |  234 lines

  1. //
  2. // "$Id: forms.cxx,v 1.4 1999/01/07 19:17:53 mike Exp $"
  3. //
  4. // Another forms demo for the Fast Light Tool Kit (FLTK).
  5. //
  6. // This is an XForms program with very few changes.
  7. // Search for "fltk" to find all changes necessary to port to fltk.
  8. //
  9. // This demo show the different boxtypes. Note that some
  10. // boxtypes are not appropriate for some objects
  11. //
  12. // Copyright 1998-1999 by Bill Spitzak and others.
  13. //
  14. // This library is free software; you can redistribute it and/or
  15. // modify it under the terms of the GNU Library General Public
  16. // License as published by the Free Software Foundation; either
  17. // version 2 of the License, or (at your option) any later version.
  18. //
  19. // This library is distributed in the hope that it will be useful,
  20. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  22. // Library General Public License for more details.
  23. //
  24. // You should have received a copy of the GNU Library General Public
  25. // License along with this library; if not, write to the Free Software
  26. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  27. // USA.
  28. //
  29. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  30. //
  31.  
  32. #include <FL/forms.H> // changed for fltk
  33.  
  34. static int border = 1; // changed from FL_TRANSIENT for fltk
  35. // (this is so the close box and Esc work to close the window)
  36.  
  37. typedef struct { int val; char *name; } VN_struct;
  38. #define VN(a) {a,#a}
  39.  
  40. // static VN_struct gmode[] =
  41. // {
  42. //   VN(StaticGray), VN(GrayScale), VN(StaticColor),
  43. //   VN(PseudoColor), VN(TrueColor), VN(DirectColor),
  44. // };
  45.  
  46. static VN_struct btypes[]=
  47. {
  48.    {FL_NO_BOX,"no box"},
  49.    {FL_UP_BOX, "up box"},
  50.    {FL_DOWN_BOX,"down box"},
  51.    {FL_BORDER_BOX,"border box"},
  52.    {FL_SHADOW_BOX,"shadow box"},
  53.    {FL_FLAT_BOX,"flat box"},
  54.    {FL_FRAME_BOX,"frame box"},
  55.    {FL_EMBOSSED_BOX,"embossed box"},
  56.    {FL_ROUNDED_BOX,"rounded box"},
  57.    {FL_RFLAT_BOX,"rflat box"},
  58.    {FL_RSHADOW_BOX,"rshadow box"}, // renamed for fltk
  59.    {FL_OVAL_BOX,"oval box"},
  60.    {FL_ROUNDED3D_UPBOX,"rounded3d upbox"},
  61.    {FL_ROUNDED3D_DOWNBOX,"rounded3d downbox"},
  62.    {FL_OVAL3D_UPBOX,"oval3d upbox"},
  63.    {FL_OVAL3D_DOWNBOX,"oval3d downbox"},
  64.    /* sentinel */
  65.    {-1}
  66. };
  67.  
  68. #include "srs.xbm"
  69.  
  70. /*************** Callback **********************/
  71.  
  72. FL_FORM *form;
  73. Fl_Widget *tobj[18], *exitob, *btypeob, *modeob;
  74.  
  75. void 
  76. boxtype_cb (Fl_Widget * ob, long)
  77. {
  78.   int i, req_bt = fl_get_choice(ob) - 1;
  79.   static int lastbt = -1;
  80.  
  81.   if(lastbt != req_bt)
  82.   {
  83.      fl_freeze_form (form);
  84.      fl_redraw_form (form);
  85.      for (i = 0; i < 18; i++)
  86.         fl_set_object_boxtype (tobj[i], (Fl_Boxtype)btypes[req_bt].val);
  87.      fl_unfreeze_form (form);
  88.      lastbt = req_bt;
  89.      fl_redraw_form(form); // added for fltk
  90.   }
  91. }
  92.  
  93. void 
  94. mode_cb (Fl_Widget *, long)
  95. {
  96. //   static int lval = -1;
  97. //   int val = fl_get_choice (ob) -1;
  98. //   int  db = 0;
  99.  
  100. //   if (val == lval || val < 0)
  101. //     return;
  102.  
  103. //   fl_hide_form (form);
  104. //   if (!fl_mode_capable (gmode[val].val, 0))
  105. //   {
  106. //       fl_set_choice(ob, lval);
  107. //       val = lval;
  108. //   }
  109.  
  110. //   fl_set_graphics_mode (gmode[val].val, db);
  111. //   fl_show_form (form, FL_PLACE_GEOMETRY, border, "Box types");
  112.  
  113. //   lval = val;
  114. }
  115.  
  116. /*************** Creation Routines *********************/
  117.  
  118. void 
  119. create_form_form (void)
  120. {
  121.   Fl_Widget *obj;
  122.  
  123.   form = fl_bgn_form(FL_NO_BOX, 720, 520);
  124.   obj = fl_add_box(FL_UP_BOX, 0, 0, 720, 520, "");
  125.   fl_set_object_color(obj, FL_BLUE, FL_COL1);
  126.   obj = fl_add_box(FL_DOWN_BOX, 10, 90, 700, 420, "");
  127.   fl_set_object_color(obj, FL_COL1, FL_COL1);
  128.   obj = fl_add_box(FL_DOWN_BOX, 10, 10, 700, 70, "");
  129.   fl_set_object_color(obj, FL_SLATEBLUE, FL_COL1);
  130.   tobj[0] = obj = fl_add_box(FL_UP_BOX, 30, 110, 110, 110, "Box");
  131.   tobj[1] = obj = fl_add_text(FL_NORMAL_TEXT, 30, 240, 110, 30, "Text");
  132.   tobj[2] = obj = fl_add_bitmap(FL_NORMAL_BITMAP, 40, 280, 90, 80, "Bitmap");
  133.   fl_set_object_lcol(obj, FL_BLUE);
  134.   tobj[3] = obj = fl_add_chart(FL_BAR_CHART, 160, 110, 160, 110, "Chart");
  135.   tobj[4] = obj = fl_add_clock(FL_ANALOG_CLOCK, 40, 390, 90, 90, "Clock");
  136. //fl_set_object_dblbuffer(tobj[4],1); // removed for fltk
  137.   tobj[5]=obj=fl_add_button(FL_NORMAL_BUTTON, 340, 110, 120, 30, "Button");
  138.   tobj[6]=obj=fl_add_lightbutton(FL_PUSH_BUTTON,340,150,120,30,"Lightbutton");
  139.   tobj[7]=obj=fl_add_roundbutton(FL_PUSH_BUTTON,340,190,120,30,"Roundbutton");
  140.   tobj[8]=obj=fl_add_slider(FL_VERT_SLIDER, 160, 250, 40, 230, "Slider");
  141.   tobj[9]=obj=fl_add_valslider(FL_VERT_SLIDER, 220, 250, 40, 230, "Valslider");
  142.   tobj[10]=obj=fl_add_dial (FL_LINE_DIAL, 280, 250, 100, 100, "Dial");
  143.   tobj[11]=obj=fl_add_positioner(FL_NORMAL_POSITIONER,280,380,150,100, "Positioner");
  144.   tobj[12]=obj=fl_add_counter (FL_NORMAL_COUNTER,480,110,210,30, "Counter");
  145.   tobj[13]=obj=fl_add_input (FL_NORMAL_INPUT, 520,170,170,30, "Input");
  146.   tobj[14]=obj=fl_add_menu (FL_PUSH_MENU, 400, 240, 100, 30, "Menu");
  147.   tobj[15]=obj=fl_add_choice (FL_NORMAL_CHOICE, 580, 250, 110, 30, "Choice");
  148.   tobj[16]=obj=fl_add_timer (FL_VALUE_TIMER, 580, 210, 110, 30, "Timer");
  149. //fl_set_object_dblbuffer(tobj[16], 1); // removed for fltk
  150.   tobj[17]=obj=fl_add_browser (FL_NORMAL_BROWSER,450,300,240, 180, "Browser");
  151.   exitob=obj= fl_add_button (FL_NORMAL_BUTTON, 590, 30, 100, 30, "Exit");
  152.   btypeob=obj= fl_add_choice (FL_NORMAL_CHOICE,110,30, 130, 30, "Boxtype");
  153.   fl_set_object_callback (obj, boxtype_cb, 0);
  154.   modeob = obj=fl_add_choice(FL_NORMAL_CHOICE,370,30,130,30,"Graphics mode");
  155.   fl_set_object_callback (obj, mode_cb, 0);
  156.   fl_end_form ();
  157. }
  158. /*---------------------------------------*/
  159.  
  160. void 
  161. create_the_forms (void)
  162. {
  163.   create_form_form ();
  164. }
  165.  
  166. /*************** Main Routine ***********************/
  167.  
  168. char *browserlines[] = {
  169.    " ", "@C1@c@l@bObjects Demo",   " ",
  170.    "This demo shows you all",      "objects that currently",
  171.    "exist in the Forms Library.",  " ",
  172.    "You can change the boxtype",   "of the different objects",
  173.    "using the buttons at the",     "top of the form. Note that",
  174.    "some combinations might not",  "look too good. Also realize",
  175.    "that for all object classes",  "many different types are",
  176.    "available with different",     "behaviour.", " ",
  177.    "With this demo you can also",  "see the effect of the drawing",
  178.    "mode on the appearance of the","objects.",
  179.    0
  180. };
  181.  
  182.  
  183. int
  184. main (int argc, char *argv[])
  185. {
  186.   FL_COLOR c = FL_BLACK;
  187.   char **p;
  188.   VN_struct *vn;
  189.  
  190.   fl_initialize(&argc, argv, "FormDemo", 0, 0);
  191.   create_the_forms ();
  192.   fl_set_bitmap_data (tobj[2], sorceress_width, sorceress_height, sorceress_bits);
  193.   fl_add_chart_value (tobj[3], 15, "item 1", c++);
  194.   fl_add_chart_value (tobj[3], 5, "item 2", c++);
  195.   fl_add_chart_value (tobj[3], -10, "item 3", c++);
  196.   fl_add_chart_value (tobj[3], 25, "item 4", c++);
  197.   fl_set_menu (tobj[14], "item 1|item 2|item 3|item 4|item 5");
  198.   fl_addto_choice (tobj[15], "item 1");
  199.   fl_addto_choice (tobj[15], "item 2");
  200.   fl_addto_choice (tobj[15], "item 3");
  201.   fl_addto_choice (tobj[15], "item 4");
  202.   fl_addto_choice (tobj[15], "item 5");
  203.   fl_set_timer (tobj[16], 1000.0);
  204.  
  205.   for ( p = browserlines; *p; p++)
  206.      fl_add_browser_line (tobj[17], *p);
  207.  
  208.   for ( vn = btypes; vn->val >= 0; vn++)
  209.     fl_addto_choice(btypeob, vn->name);
  210.  
  211. //   {
  212. //     int i;
  213. //     VN_struct *g = gmode, *gs = g + sizeof (gmode) / sizeof (gmode[0]);
  214. //     for (i = 1; g < gs; g++, i++)
  215. //     {
  216. //       fl_addto_choice (modeob, g->name);
  217. //       if(!fl_mode_capable(g->val, 0))
  218. //         fl_set_choice_item_mode(modeob, i, FL_PUP_GRAY);
  219. //     }
  220. //   }
  221. //   fl_set_choice (modeob, fl_vmode+1);
  222.  
  223.   fl_show_form (form, FL_PLACE_MOUSE, border, "Box types");
  224.  
  225.   while (fl_do_forms () != exitob)
  226.      ;
  227.  
  228.   return 0;
  229. }
  230.  
  231. //
  232. // End of "$Id: forms.cxx,v 1.4 1999/01/07 19:17:53 mike Exp $".
  233. //
  234.